import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterdemo/pages/home.dart';
import 'package:flutterdemo/pages/my.dart';
import 'package:flutterdemo/pages/setting.dart';

class Tabs extends StatefulWidget {
  final index;

  const Tabs({Key? key, this.index = 0}) : super(key: key);

  @override
  _TabsState createState() => _TabsState(this.index);
}

class _TabsState extends State<Tabs> {
  // int currentIndex =0;
  int _currentPostion = 0;

  List pageList = [Home(), Setting(), My(), My(), My()];

  _TabsState(index) {
    this._currentPostion = index;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("标题栏"),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("首页")),
          BottomNavigationBarItem(
              icon: Icon(Icons.settings), title: Text("设置")),
          BottomNavigationBarItem(
              icon: Icon(Icons.my_library_add), title: Text("我的")),
          BottomNavigationBarItem(
              icon: Icon(Icons.my_library_add), title: Text("我的")),
          BottomNavigationBarItem(
              icon: Icon(Icons.my_library_add), title: Text("我的")),
        ],
        currentIndex: _currentPostion,
        onTap: (index) {
          print(index);
          setState(() {
            _currentPostion = index;
          });
        },
        fixedColor: Colors.red,
        type: BottomNavigationBarType.fixed,
      ),
      drawer: Drawer(
        child: Column(
          children: [
            UserAccountsDrawerHeader(
              accountName: Text('林红峰'),
              accountEmail: Text('17625935946@163.com'),
              currentAccountPicture: CircleAvatar(
                backgroundImage:
                    NetworkImage('https://www.itying.com/images/flutter/3.png'),
              ),
              otherAccountsPictures: [Icon(Icons.home)],
              decoration: BoxDecoration(
                  image: DecorationImage(
                      fit: BoxFit.fill,
                      image: NetworkImage(
                          'https://www.itying.com/images/flutter/2.png'))),
            ),
            ListTile(
              leading: Icon(Icons.home),
              title: Text("我的空间"),
            ),
            Divider(),
            ListTile(
              leading: Icon(Icons.people),
              title: Text("我的朋友圈"),
            ),
            Divider(),
            ListTile(
              leading: Icon(Icons.settings),
              title: Text("用户中心"),
              onTap: () => {
                Navigator.of(context).pop(),
                Navigator.of(context).pushNamed('/user')
              },
            ),
          ],
        ),
      ),
      endDrawer: Drawer(
        child: Text('右侧侧边栏'),
      ),
      /* appBar: AppBar(
        title: Text("我是标题栏"),
      ),*/
      body: this.pageList[_currentPostion],
    );
  }
}
